package dao

import (
	"iot-bridge/iot_cmd_up/distribute/conf"
	"iot-bridge/iot_cmd_up/distribute/dao/mysql"
	"iot-bridge/iot_cmd_up/distribute/dao/producer"
	"iot-bridge/iot_cmd_up/distribute/dao/redis"

	log "common/log4go.v1"
)

func Init() error {
	if err := mysql.Reload(conf.Conf.Mysql); err != nil {
		log.Error("mysql.Reload(%v,%s) error(%v)", conf.Conf.Mysql, conf.Conf.Base.Debug, err)
		return err
	}
	if err := producer.Init(); err != nil {
		log.Error("producer.Init() error(%v)", err)
		return err
	}
	if err := redis.Init(conf.Conf.Redis); err != nil {
		log.Error("redis.Init(%v) error(%v)", conf.Conf.Redis, err)
		return err
	}
	return nil
}

func Close() {
	redis.Close()
	producer.Close()
	mysql.Close()
}
